<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8">
		<title>计算属性练习</title>
	</head>
	<body>
		
		<div id="app">
			<!-- 进行字符串拼接 -->
			<h1>{{msg}}</h1>
			<h1>{{msgComputed}}</h1>
		</div>
		
		
		<script type="text/javascript" src="../js/vue.min.js"></script>
		<script>
			
			const app = new Vue({
				el: "#app",
				data: { 
					id : "110",
					name : "公安局"
				},
				computed: {
					msg : {
						//取值时调用对象的get方法
						get : function(){
							return this.id + " " + this.name;
						},
						//赋值时调用对象的set方法   一般条件下没有set方法,所以可以简化代码
						set : function(newValue){
							const value = newValue.split(" ");
							this.id = value[0];
							this.name = value[1];
						}
					},
					
					msgComputed : function(){
						return this.id + " " + this.name;
					}
					
				}
			});
			
			
		</script>
	</body>
</html>
